package com.EVO.controller;

import com.EVO.dao.ProvinceDao;
import com.EVO.entity.Province;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class QueryJsonServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String strProId = request.getParameter("proid");
        String json = "{}";
        if(strProId != null && strProId.trim().length() > 0){
            ProvinceDao dao = new ProvinceDao();
            Province province = dao.getProvince(Integer.valueOf(strProId));
            ObjectMapper om = new ObjectMapper();
            json = om.writeValueAsString(province);
        }
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print(json);
    }
}
